package com.shopping.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.shopping.po.Order;
import com.shopping.po.User;
import com.shopping.service.OrderService;

@Controller
public class OrderController {
	@Autowired
	private OrderService orderService;
	
	@RequestMapping("/registerSuccess")
	public String registerSuccess() {
		return "registerSuccess";
	}
	
	//查看状态为1的 待发货的商品
	@RequestMapping("/allOrder")
	public String allOrder(Model model,HttpSession session) {
		User user= (User) session.getAttribute("user");
		List<Order> order = orderService.findOrderByAll(user);
		model.addAttribute("order",order);
		return "personal";
	}
	
	@RequestMapping("/waiting")
	public String waiting(Model model,HttpSession session) {
		String status = "1";
		User user= (User) session.getAttribute("user");
		String username = user.getUsername();
		Map<String, String> map = new HashMap<String, String>();
		map.put("status", status);
		map.put("username",username);
		List<Order> order = orderService.findOrderByStatus(map);
		model.addAttribute("order",order);
		return "waiting";	
	}
	
	
	@RequestMapping("/already")
	public String already(Model model,HttpSession session) {
		String status = "2";
		User user= (User) session.getAttribute("user");
		String username = user.getUsername();
		Map<String, String> map = new HashMap<String, String>();
		map.put("status", status);
		map.put("username",username);
		List<Order> order = orderService.findOrderByStatus(map);
		model.addAttribute("order",order);
		return "already";	
	}
	@RequestMapping("/signed")
	public String signed(Model model,HttpSession session) {
		String status = "3";
		User user= (User) session.getAttribute("user");
		String username = user.getUsername();
		Map<String, String> map = new HashMap<String, String>();
		map.put("status", status);
		map.put("username",username);
		List<Order> order = orderService.findOrderByStatus(map);
		model.addAttribute("order",order);
		return "signed";	
	}
}
